package com.teacold.utils.toast;

import android.content.Context;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.teacold.customdemo.R;

public class CustomToast{
    private Toast mToast;

    public CustomToast( Context mContext,int mLayout,String mTips,int imaage) {
        initToast(mContext,mLayout,mTips,imaage);
    }
    public CustomToast( Context mContext,int mLayout,String mTips) {
        initToast(mContext,mLayout,mTips,0);
    }
   public void initToast(Context mContext,int mLayout,String mTips,int imaage){
      if(mToast==null){
          mToast=new Toast(mContext);
      }
          View view=LayoutInflater.from(mContext).inflate(mLayout,null);
          view.getBackground().setAlpha(200);
          TextView textView = (TextView) view.findViewById(R.id.toast_text);
          ImageView imageView=view.findViewById(R.id.toast_image);
          if(imaage==0){
              imageView.setVisibility(View.GONE);
          }else {
              imageView.setVisibility(View.VISIBLE);
              imageView.setImageResource(imaage);
          }
          textView.setText(mTips);
          mToast.setGravity(Gravity.CENTER, 0, 0);
          mToast.setDuration(Toast.LENGTH_LONG);
          mToast.setView(view);
       Log.e("bbbbbbbbbbb","是否显示toast");
   }
   public void show(){
       mToast.show();
       Log.e("bbbbbbbbbbb","show");
   }
    public void cancel(){
        mToast.cancel();
    }

}

